#include "const.h"

void v_array_empty(var_t v) {
	if (v->flags & VAR_CONST_BIT)
		return;

	if (v->flags & VAR_SYMLINK_BIT) {
		v_array_empty(v->value.symlink);
		return;
	}

	if (~v->flags & VAR_ARRAY_BIT)
		return;

	//
	//	NOTE
	//	This for loop is uses v->array.i because I'm going to add in handlers
	//	that could be scripted. As such, the array's official 'i' value should
	//	be used.
	//
	for(v->array.i=0; v->array.i<v->array.n; v->array.i++) {
		v->flags &= ~(VAR_EXPANDEDI_BIT|VAR_ARRAYFETCHED_BIT);

		if (v->array.members[v->array.i])
			i_delete((void *)v->array.members[v->array.i]);
	}

	v->flags &= ~(VAR_EXPANDEDI_BIT|VAR_EXPANDEDN_BIT|VAR_ARRAYFETCHED_BIT);

	i_delete((void *)v->array.members);
	v->array.members = (char **)0;

	v->array.capacity = 0;
	v->array.n = 0;
	v->array.i = 0;

	if (v->value.text) {
		i_delete((void *)v->value.text);
		v->value.text = (char *)0;
	}

	if (v->expanded) {
		i_delete((void *)v->expanded);
		v->expanded = (char *)0;
	}
}
